第 19 期 Python 程式設計入門-作業任務4


Jan 11, 2024
  1. 問答申論題
    Python 字串物件的方法 str.title()
    官方描述介紹:

    Return a titlecased version of the binary sequence where words start with an uppercase ASCII character and the remaining characters are lowercase. Uncased byte values are left unmodified.

意思即為透過str.title()這個物件方法,將字串單字首字元以大寫回傳,其餘字元為小寫。

使用範例:

text = 'hello world, how are you today?'
print(text.title())
#得到'Hello World, How Are You Today?'

2.程式設計實作題
設計一個程式:讓使用者可以輸入英文字串,並透過取出使用者輸入的字串將最後一個字元取出轉成英文大寫後印出結果。

user_text = input('請輸入英文字串: ')
if user_text.isalpha():
  print(user_text[-1].upper())
else:
  print('請輸入英文字串')

(此方法無法判斷使用者輸入中文內容)







你可能感興趣的文章

570. Managers with at Least 5 Direct Reports

570. Managers with at Least 5 Direct Reports

《鳥哥 Linux 私房菜:基礎篇》Chapter 03 - 安裝 CentOS7.x

《鳥哥 Linux 私房菜:基礎篇》Chapter 03 - 安裝 CentOS7.x

金魚系列、RWD 中

金魚系列、RWD 中






留言討論






2
2
2